package com.origin.app.app_list

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.origin.app.MyApplication
import com.origin.app.app_list.bean.AppInfo
import com.origin.app.app_list.bean.AppList
import com.origin.app.bean.WeatherBean
import com.origin.baselibrary.expand.MutableListLiveData
import com.origin.baselibrary.viewmodel.BaseViewModel
import com.origin.netlibrary.NetUtils.getNet
import com.origin.netlibrary.listener.Response
import com.origin.netlibrary.netapi.RequestFormat
import kotlinx.coroutines.delay
import java.io.File

class AppListViewModel : BaseViewModel() {
    val appInfoList = MutableListLiveData<AppInfo>()
    private val restService: RequestFormat by lazy {
        MyApplication.getInstance().retrofitManager.requestFormat
    }

    fun getAppList() {
        viewModelSuspend {
            val map = mapOf("city" to "北京", "key" to "6c11b7969beec525c7bb8530e39f4442")
            val appList = restService.get(
                "http://mock.presstime.cn/mock/63043df2870a85006347d87b/app_list/list.do",
                map
            )
                .getNet(this, object : Response<AppList>() {})
            appList.apply {
                Log.e("code", "$code")
                appInfoList.clearAndAll(this.data.app_list)
            }
        }
    }
}